package edu.fiu.cis.nursing.server.db.hibernate;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

public final class HibernateUtil {

	private static final SessionFactory s_session_factory;
	static {
		try {
			AnnotationConfiguration configuration = new AnnotationConfiguration();
			configuration.configure();

			s_session_factory = configuration.buildSessionFactory();
		} catch (Throwable ex) {
			// Log exception!
			throw new ExceptionInInitializerError(ex);
		}
	}

	public static Session openSession() {
		Session session = s_session_factory.openSession();
		return session;
	}

	public static void closeSession(Session session) {
		session.close();
	}

	public static SessionFactory getSessionFactory() {
		return s_session_factory;
	}

}